package com.demo.datastructure.reorder.selectorSort;

/**
 * @description: 选择排序的优化
 * @author: ljr
 * @time: 2021/5/7 21:30
 */
public class MySelectorSort4 {

    public static void selectorSort(int[] args, int n){
        for(int i = 0; i < n-1; i++){
            int min = args[i];
            int k = i+1;

            int m = -1;
            for(; k < n; k++){
                if(args[k] < min){
                    min = args[k];
                    m = k;
                }
            }

            args[m] = args[i];
            args[i] = min;
        }
    }

    public static void main(String[] args) {
        int[] nums = new int[]{4,5,6,3,2,1};
        MySelectorSort4.selectorSort(nums,nums.length);
        for(int num : nums){
            System.out.println(num);
        }
    }
}
